package com.lhj.springboot.web.controller;

import com.lhj.springboot.web.pojo.Person;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description
 * @Author lhj
 * @Date 2024/6/16 10:28
 */
@Controller
public class WelcomeController {
    
    @GetMapping("wel")
    public String wel(@RequestParam String name, Model model) {
        model.addAttribute("msg", name);
        String formatted = String.format("<span style=\"color: red\">%s</span>", name);
        model.addAttribute("name", formatted);
        
        String style = "color: green";
        model.addAttribute("style", style);
        
        String imgStyle = "width: 120px; height: 120px";
        model.addAttribute("imgStyle", imgStyle);
        
        //welcome 逻辑视图名称
        //物理视图 = 前缀 + 逻辑视图名称 + 后缀
        //真实路径 = /templates/welcome.html
        return "welcome";
    }
    
    @GetMapping("list")
    public String list(Model model) {
        List<Person> personList = List.of(
                new Person(1L, "lhj", "lhj@163.com", 17, "pm"),
                new Person(2L, "lhj2", "lhj2@163.com", 15, "admin"),
                new Person(3L, "lhj3", "lhj3@163.com", 18, "hr"),
                new Person(4L, "lhj4", "lhj@163.com", 20, "pm"),
                new Person(5L, "lhj5", "lhj2@163.com", 12, "admin"),
                new Person(6L, "lhj6", "lhj3@163.com", 20, "hr")
        );
        model.addAttribute("personList", personList);
        
        int i = 10 / 0;
        
        return "list";
    }
    
   /* @ResponseBody
    @ExceptionHandler(value = {Exception.class})
    public String handleException(Exception e) {
        return "/(ㄒoㄒ)/~~" + e.getMessage();
    }*/
}
